/*
 * @Author: biankai
 * @Date: 2021-04-19 18:47:04
 * @LastEditTime: 2021-11-05 14:35:23
 * @LastEditors: biankai
 * @FilePath: /gitee/devops_service/src/controllers/kubernetes/Service.controller.ts
 */
import { Controller, Inject, Get, Query, Param, Post, Put, Delete, Body } from '@nestjs/common';
import { ApiCreatedResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import * as kubernetes from '@kubernetes/client-node';
import { ServiceService } from '../../services/kubernetes/service.service';

@ApiTags('K8s-服务')
@Controller('kubernetes/service')
export class ServiceController {
    constructor(@Inject(ServiceService) private readonly k8sService: ServiceService) {
    }

    @ApiOperation({ summary: '获取指定命名空间下的服务节点', description: '说明 : 调用此接口,可获得指定命名空间下的服务节点' })
    @ApiCreatedResponse({
        description: 'The record has been successfully created.',
        type: kubernetes.V1Namespace
    })
    @Get(':namespaceName')
    async listK8sNamespace(@Param('namespaceName') namespaceName) {
        return await this.k8sService.listNamespacedService(namespaceName)
    }

    @ApiOperation({ summary: '获取指定命名空间下的单个服务节点详情', description: '说明 : 调用此接口,可获得指定命名空间下的单个服务节点详情' })
    @Get(':namespaceName/:name')
    async singleK8sNamespace(@Param('namespaceName') namespaceName, @Param('name') name) {
        return await this.k8sService.readNamespacedService(namespaceName, name)
    }

    @ApiOperation({ summary: '新增指定命名空间下的服务节点', description: '说明 : 调用此接口,可新增新增指定命名空间下的服务节点' })
    @Post(':namespaceName')
    async createK8sNamespace(@Param('namespaceName') namespaceName, @Body() serviceDto) {
        return await this.k8sService.createNamespacedService(namespaceName, serviceDto)
    }

    @ApiOperation({ summary: '修改指定命名空间下的服务节点', description: '说明 : 调用此接口,可修改指定命名空间下的服务节点' })
    @Put(':namespaceName/:name')
    async replaceK8sNamespace(@Param('namespaceName') namespaceName, @Param('name') name, @Body() serviceDto) {
        return await this.k8sService.replaceNamespacedService(namespaceName, name, serviceDto)
    }
    @ApiOperation({ summary: '删除指定命名空间下的服务节点', description: '说明 : 调用此接口,可删除指定命名空间下的服务节点' })
    @Delete(':namespaceName/:name')
    async deleteK8sNamespace(@Param('namespaceName') namespaceName, @Param('name') name) {
        return await this.k8sService.deleteNamespacedService(namespaceName, name)
    }


}